package com.test11_泛型;

/**
 * 泛型基本定义
 */
public class YootkDemo_01 {

    public static void main(String[] args) {
        {
            Message<String> message = new Message<String>();
            message.setContent("www.yootk.com");
            message.send();
        }
        {
            // JDK1.7之后简化写法
            Message<Integer> message = new Message<>();
            message.setContent(99);
            int value = message.getContent();
            System.out.println("【message中的消息内容】" + value);
        }
        {
            // 不指定泛型类型，默认是Object类型
            Message message = new Message();
            message.setContent(66);
            Object value = message.getContent();
            System.out.println(value);
        }
    }
}

class Message<T> {  // 定义泛型
    private T content;

    public void setContent(T content) {
        this.content = content;
    }

    public T getContent() {
        return this.content;
    }

    public void send() {
        System.out.println("【消息发送】" + this.content);
    }
}
